using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Media;
namespace Microsoft.Expression.Media
{
	[TypeConverter(typeof(GeometryEffectConverter))]
	public abstract class GeometryEffect : DependencyObject
	{
		private class NoGeometryEffect : GeometryEffect
		{
			protected override bool UpdateCachedGeometry(Geometry input)
			{
				this.cachedGeometry = input;
				return false;
			}
			protected override GeometryEffect DeepCopy()
			{
				return new GeometryEffect.NoGeometryEffect();
			}
			public override bool Equals(GeometryEffect geometryEffect)
			{
				return geometryEffect == null || geometryEffect is GeometryEffect.NoGeometryEffect;
			}
		}
		public static readonly DependencyProperty GeometryEffectProperty;
		private static GeometryEffect defaultGeometryEffect;
		protected Geometry cachedGeometry;
		private bool effectInvalidated;
		public static GeometryEffect DefaultGeometryEffect
		{
			get
			{
				GeometryEffect arg_14_0;
				if ((arg_14_0 = GeometryEffect.defaultGeometryEffect) == null)
				{
					arg_14_0 = (GeometryEffect.defaultGeometryEffect = new GeometryEffect.NoGeometryEffect());
				}
				return arg_14_0;
			}
		}
		public Geometry OutputGeometry
		{
			get
			{
				return this.cachedGeometry;
			}
		}
		protected internal DependencyObject Parent
		{
			get;
			private set;
		}
		public static GeometryEffect GetGeometryEffect(DependencyObject obj)
		{
			return (GeometryEffect)obj.GetValue(GeometryEffect.GeometryEffectProperty);
		}
		public static void SetGeometryEffect(DependencyObject obj, GeometryEffect value)
		{
			obj.SetValue(GeometryEffect.GeometryEffectProperty, value);
		}
		private static void OnGeometryEffectChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
		{
			GeometryEffect geometryEffect = e.get_OldValue() as GeometryEffect;
			GeometryEffect geometryEffect2 = e.get_NewValue() as GeometryEffect;
			if (geometryEffect != geometryEffect2)
			{
				if (geometryEffect != null && obj.Equals(geometryEffect.Parent))
				{
					geometryEffect.Detach();
				}
				if (geometryEffect2 != null)
				{
					if (geometryEffect2.Parent != null)
					{
						GeometryEffect geometryEffect3 = geometryEffect2.CloneCurrentValue();
						obj.SetValue(GeometryEffect.GeometryEffectProperty, geometryEffect3);
						return;
					}
					geometryEffect2.Attach(obj);
				}
			}
		}
		public GeometryEffect CloneCurrentValue()
		{
			return this.DeepCopy();
		}
		protected abstract GeometryEffect DeepCopy();
		public abstract bool Equals(GeometryEffect geometryEffect);
		static GeometryEffect()
		{
			GeometryEffect.GeometryEffectProperty = DependencyProperty.RegisterAttached("GeometryEffect", typeof(GeometryEffect), typeof(GeometryEffect), new DrawingPropertyMetadata(GeometryEffect.DefaultGeometryEffect, DrawingPropertyMetadataOptions.AffectsRender, new PropertyChangedCallback(GeometryEffect.OnGeometryEffectChanged)));
			DrawingPropertyMetadata.DrawingPropertyChanged += delegate(object sender, DrawingPropertyChangedEventArgs e)
			{
				GeometryEffect geometryEffect = sender as GeometryEffect;
				if (geometryEffect != null && e.Metadata.AffectsRender)
				{
					geometryEffect.InvalidateGeometry(InvalidateGeometryReasons.PropertyChanged);
				}
			};
		}
		public bool InvalidateGeometry(InvalidateGeometryReasons reasons)
		{
			if (!this.effectInvalidated)
			{
				this.effectInvalidated = true;
				if (reasons != InvalidateGeometryReasons.ParentInvalidated)
				{
					GeometryEffect.InvalidateParent(this.Parent);
				}
				return true;
			}
			return false;
		}
		public bool ProcessGeometry(Geometry input)
		{
			bool flag = false;
			if (this.effectInvalidated)
			{
				flag |= this.UpdateCachedGeometry(input);
				this.effectInvalidated = false;
			}
			return flag;
		}
		protected abstract bool UpdateCachedGeometry(Geometry input);
		protected internal virtual void Detach()
		{
			this.effectInvalidated = true;
			this.cachedGeometry = null;
			if (this.Parent != null)
			{
				GeometryEffect.InvalidateParent(this.Parent);
				this.Parent = null;
			}
		}
		protected internal virtual void Attach(DependencyObject obj)
		{
			if (this.Parent != null)
			{
				this.Detach();
			}
			this.effectInvalidated = true;
			this.cachedGeometry = null;
			if (GeometryEffect.InvalidateParent(obj))
			{
				this.Parent = obj;
			}
		}
		private static bool InvalidateParent(DependencyObject parent)
		{
			IShape shape = parent as IShape;
			if (shape != null)
			{
				shape.InvalidateGeometry(InvalidateGeometryReasons.ChildInvalidated);
				return true;
			}
			GeometryEffect geometryEffect = parent as GeometryEffect;
			if (geometryEffect != null)
			{
				geometryEffect.InvalidateGeometry(InvalidateGeometryReasons.ChildInvalidated);
				return true;
			}
			return false;
		}
	}
}
